/****************************************************************************
 * @file    : sysport.c
 * @author  : novosense
 * @version : V1.0
 * @Date    : 2022/3/7
 * @brief   :
 * @note
 * Copyright (C) 2022 novosense All rights reserved.
 ****************************************************************************/

#include "include.h"
#define __XTAL            (32000000UL)

void PrintfInit(int baudRate)
{
}

void delay_ms(uint32_t n)
{
    for (uint32_t i = 0; i < n; i++) {
        delay_us(1000);
    }
}

void delay_us(uint32_t n)
{
    /* set reload register, set period = 100ms */
    SysTick->LOAD = (uint32_t)(32 - 1UL);
    SysTick->VAL  = 0UL; /* Load the SysTick Counter Value */
    SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk;
    for (uint32_t i = 0; i < n; i++) {
        while (!(SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk))
            ;
    }
    SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
}
